package com.usian.controller;

import com.alibaba.fastjson.JSON;
import com.usian.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.net.UnknownServiceException;

@Controller
public class provider {


    @Autowired
    private KafkaTemplate<String,Object> kafkaTemplate;

    @GetMapping("send")
    @ResponseBody
    public String send(){

        User user =new User();
        user.setUsername("张三");
        user.setPassword("spspspspspsps");

        kafkaTemplate.send("topic2", JSON.toJSONString(user));

        return "ok";
    }
}
